package com.lollipop.rabbitmq.one;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author: Lollipop
 * @Date: 2021-10-03 11:47
 * @Description:
 */
public class Consumer {
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        // 从连接工厂获取连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.247.129");
        connectionFactory.setUsername("lollipop");
        connectionFactory.setPassword(("lollipop"));
        Connection connection = connectionFactory.newConnection();
        // 由连接获取信道
        Channel channel = connection.createChannel();
        // 消费者消费消息
        channel.basicConsume(QUEUE_NAME, true,
                (consumerTag, message) -> System.out.println("消费：{}" + new String(message.getBody())),
                consumerTag -> System.out.println("消息被中断"));
    }
}
